package com.ndhutu.ee.util.dwz.suo;

import com.ndhutu.ee.util.DateUtil;
import com.ndhutu.ee.util.dwz.DwzConfig;
import com.ndhutu.ee.util.http.OKHttpUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author AppiJ
 * @Date 2020/5/7 17:43
 */
public class DwzSuoUtil {
    final static String CREATE_API = "http://suo.im/api.htm";
    final static Integer EXPIREDATE = 100;  //过期时间（单位：月）

    /**
     * 创建短链接
     * @Author AppiJ
     * @Date 2020/5/7 17:48
     * @param
     * @return
     */
    public static  String createShortUrl(String longUrl, DwzConfig config) throws Exception{

        Map<String, String> params = new HashMap<String, String>();
        params.put("url", longUrl);
        params.put("key", config.getKey());
        params.put("expireDate", DateUtil.getDateByMonth(EXPIREDATE));

        String resultJson = OKHttpUtil.get(CREATE_API, params);

        return resultJson;
    }

    public static void main(String[] args) {
        try{
            System.out.println(createShortUrl("http://share.pp.51cyhy.com/download/index.html?channelCode=499778", new DwzConfig() {
                public String getToken() {
                    return null;
                }

                public String getKey() {
                    return "5eb3d262b1b63c4a8d3cc5fd@3c1af7c752f89b6446a869e747381966";
                }
            }));
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
